--[[
  -- 返回 + 福利
  -----------------------
  左边好像不用拾取，拾取 中间标题，比较快 (位置固定中间，范围怎么也比左边小)
  例如 左边-签到  ->  拾取 中间标题 签到 -> 内容操作
]]
function BackWelfare()
  -- local rightSize = {236, 148, 1854,1064}
  local rightSize = {8.135, 7.297, 1.03, 1.015} -- 内容 - 签到

  local size = {0, 102, 180, width - 102}
  local RedTable = CS_game_common_back_redpoint
  RedTable.size.android = size
  RedTable.size.ios = size
  RxLog("Back -> backWelfare -> 识别小红点")
  local loop = 0
  ::next::
  local rtn, x, y = 0, 0, 0
  local UseBackResourceRecovery = 0
  local whileLoop = RxTouchWithColor(RedTable)
  while whileLoop == 1 do
    RxLog("Back -> backWelfare -> 识别小红点 while-do")
    mSleep(1000)
    ::continue:: -- goto
    local android_point, ios_point = {0, 0}, {0, 0}
    -- 1 小红点
    -- 2
    RxLog("Back -> backWelfare ->  while-do 签到")
    rtn, x, y = RxFindTextTable(Font_game_welfare_singin_select) -- 福利-签到
    if rtn == 1 then
      RxLog("Back -> backWelfare ->  while-do 签到 - 转动条 - 蓝底")
      rtn = RxTouchWithColor(Color_game_welfare_singin_barbox2) -- 循环找色
      if rtn == 0 then
        RxLog("Back -> backWelfare ->  while-do 签到 - 转动条 2次 橙色")
        rtn = RxTouchWithColor(Color_game_welfare_singin_barbox2) -- 循环找色
      end
      if rtn == 0 then
        RxLog('Back -> backWelfare ->  while-do 签到 - 你有看见点击吗？')
        goto continue
      else
        goto next
      end
    end

    RxLog("Back -> backWelfare -> while-do 五谷丰登 - 没有适配文字")
    -- rtn, x, y = RxFindTextTable("五谷丰登") -- 福利-五谷丰登
    -- if rtn == 1 then
    --   android_point = {482, 319}
    --   ios_point = {0, 0}
    --   RxLog("Back -> backWelfare -> while-do 五谷丰登 - 酒水")
    --   RxTouch(android_point[1], android_point[2])
    --   RxLog("Back -> backWelfare -> while-do 五谷丰登 - 突破丹")
    --   android_point = {472, 578}
    --   ios_point = {0, 0}
    --   RxTouch(android_point[1], android_point[2])
    --   RxLog("Back -> backWelfare -> while-do 五谷丰登 - 石头")
    --   android_point = {1020, 578}
    --   ios_point = {0, 0}
    --   RxTouch(android_point[1], android_point[2])
    --   RxLog("Back -> backWelfare -> while-do 五谷丰登 - 领取")
    --   android_point = {762, 898}
    --   ios_point = {0, 0}
    --   RxTouch(android_point[1], android_point[2])
    --   goto next
    -- end

    RxLog("Back -> backWelfare -> while-do 宴会")
    rtn, x, y = RxFindTextTable(Font_game_welfare_banquet_select) -- 福利-宴会
    if rtn == 1 then
      RxLog("Back -> backWelfare -> while-do 宴会 - 烤鸡")
      goto next
    end

    RxLog("Back -> backWelfare -> while-do 摇钱树")
    rtn, x, y = RxFindTextTable(Font_game_welfare_cash_cow_select) -- 福利-摇钱树
    if rtn == 1 then
      RxLog("Back -> backWelfare -> while-do 摇钱树 - 最后一个 100次")
      -- 文字
      RxLog("Back -> backWelfare -> while-do 摇钱树 - +2")
      android_point = {1520, 402}
      ios_point = {0, 0}
      RxTouch(android_point[1], android_point[2])
      -- 弹框第一次 +
      RxLog("Back -> backWelfare -> while-do 摇钱树 - 确定")
      -- 需要判断 为 0 元宝 - 不然都用没了 --- ???????????????????????????????????????
      android_point = {902, 788}
      ios_point = {0, 0}
      RxTouch(android_point[1], android_point[2])
      -- 确认
      goto next
    end

    RxLog("Back -> backWelfare -> while-do 豪华卡")
    rtn, x, y = RxFindTextTable(Font_game_welfare_luxury_card_select) -- 福利-豪华卡
    if rtn == 1 then
      goto next
    end

    RxLog("Back -> backWelfare -> while-do 成长基金")
    rtn, x, y = RxFindTextTable(Font_game_welfare_growth_fund_select) -- 福利-成长基金
    if rtn == 1 then
      RxLog("Back -> backWelfare -> while-do 成长基金 - 小红点 - 全服奖励")
      RxLog("Back -> backWelfare -> while-do 成长基金 - 小红点 - 全服奖励 - 领取")
      goto next
    end

    RxLog("Back -> backWelfare -> while-do BackResourceRecovery")
    rtn = BackResourceRecovery()
    UseBackResourceRecovery = 1

    -- 弹框
    -- 目前是 签到 - 补签 ： 系统提示花费xx元宝补签吗？
    -- 取消
    -- rtn = RxTouchWithColor('取消') -- 福利-成长基金

    whileLoop = RxTouchWithColor(RedTable)
    RxLog('Back -> backWelfare -> whileLoop 小红点 是否存在='..whileLoop)
    loop = 1
  end

  if loop == 0 then
    -- 一个都没有找到，是不是，点开过？
    -- 这里再循环一遍
    RxLog("Back -> backWelfare ->  loop=0  ->>>")
  else
    return true
  end

  if UseBackResourceRecovery == 0 then
    -- 没有小红点，判断是否有资源可以 领取
    RxLog("Back -> backWelfare -> UseBackResourceRecovery BackResourceRecovery")
    rtn = BackResourceRecovery()
    -- 点击返回
    GBBackClick()
    return true
  end
  return rtn
end
